<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>添加工单物料计划</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style type="text/css">
        .detail {
            padding-right: 20px!important;
        }

        h5,
        label {
            color: #0062CC;
        }

        label {
            font-size: 14px;
        }

        .mui-navigate-right .mui-col-xs-8 {
            width: 62.666667%!important;
        }

        .mui-text-right input,
        .mui-text-right textarea {
            border: 0;
            font-size: 14px;
            font-weight: 400;
            color: #8f8f94;
            margin-bottom: 0;
            text-align: right;
        }
    </style>
</head>

<body>
    <div class="mui-content">
        <ul class="mui-table-view mui-table-view-chevron type_list_spair">
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_tast','选择任务',{wonum: api.pageParam.wonum,linetype: api.pageParam.linetype})">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">任务：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="jobtaskid">请选择任务</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail" onclick="openSaveWin('work_order_sel_materialsInfo','选择物料信息')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">SGMW ID：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="itemnum">请选择SGMW ID</span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">描述：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                    	<span class="mui-h5" id="description"></span>
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">数量：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <input type="number" onchange="linecost()" id="itemqty" placeholder="请输入数量" />
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">单位成本：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="unitcost"></span>
                        <!--<input type="text" onchange="linecost()" placeholder="请输入单位成本" id="unitcost"/>-->
                    </div>
                </div>
            </li>
            <li class="mui-table-view-cell detail">
                <div class="mui-table">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">行成本：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                    	<span class="mui-h5" id="lineText">0.00</span>
                    </div>
                </div>
            </li>
            <!--<li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_stock','选择库存地址')">
                <div class="mui-table mui-navigate-right">
                    <div class="mui-table-cell mui-col-xs-4">
                        <h5 class="mui-ellipsis">库房：</h5>
                    </div>
                    <div class="mui-table-cell mui-col-xs-8 mui-text-right">
                        <span class="mui-h5" id="stockName">请选择库房</span>
                    </div>
                </div>
            </li>-->
            <li class="mui-table-view-cell mui-checkbox">
                <label>直接发放:</label>
                <input name="checkbox1" id="directreq" type="checkbox" checked="" onchange="isdirectreq()">
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  var jobtaskid,itemnum,stockId,directreq = 1;
  apiready = function() {
      api.addEventListener({
          name: 'TastId'
      }, function(ret, err) {
      	jobtaskid = ret.value.tastnum;
        $api.html($api.byId('jobtaskid'), ret.value.description);
      });
      api.addEventListener({
          name: 'selSGWMID'
      }, function(ret, err) {
      	itemnum = ret.value.sgwm_id;
      	$api.html($api.byId('itemnum'), ret.value.sgwm_id);
      	$api.text($api.byId('unitcost'),ret.value.stdcost);
        $api.html($api.byId('description'), ret.value.sgwm_name);
      });
		api.addEventListener({
	        name: 'chooseStock'
	    }, function(ret, err) {
	        stockId = ret.value.stockId;
	        $api.html($api.byId('stockName'), ret.value.stockName)
	    });
      api.addEventListener({
  		    name:'navitembtn'
  		},function(ret, err){
  	    if(ret.type == 'right'){
          if(jobtaskid == ''||jobtaskid == null){
            Toast('请选择任务！');
            return
          }
          if(itemnum == ''||itemnum == null){
            Toast('请选择SGMW ID！');
            return
          }
          if($api.val($api.byId('itemqty')) == ''){
            Toast('请输入数量！');
            return
          }
//        if($api.html($api.byId('lineText')) == ''){
//          Toast('请输入行成本！');
//          return
//        }
//        if(stockId == ''||stockId == null){
//          Toast('请选择库房！');
//          return
//        }
//        var directreq = $api.val($api.byId('itemqty'))
          ajaxrd("savePlanMaterial",{
            wonum: jobtaskid,
            itemnum: itemnum,
            itemqty: $api.val($api.byId('itemqty')),
            unitcost: $api.text($api.byId('unitcost')),
            linecost: $api.html($api.byId('lineText')),
//          location: stockId,
            directreq: directreq
          },function(data){
            Toast('添加成功');
            api.sendEvent({
                name: 'refersh',
                extra: {
                    isrefersh: 'yes'
                }
            });
            setTimeout(function(){
              api.closeWin();
            },500)
          })
  	    }
    	})
    }

	var linecost = function () {
		if ($api.val($api.byId('itemqty')) =='' || $api.text($api.byId('unitcost')) == '') {
			return
		}
		$api.text($api.byId('lineText'),$api.val($api.byId('itemqty')) * $api.text($api.byId('unitcost')))
	}
	var isdirectreq = function () {
		if ($api.byId('directreq').checked == false) {
          	directreq = 0
          } else {
          	directreq = 1
          }
	}
</script>
</html>
